package com.letoken.platform.repo.app.redis;

import com.letoken.platform.pub.constant.RedisKeyConstant;
import com.letoken.platform.pub.util.BeanUtil;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @author letokenlabs
 * @date 2022/11/15$
 */
public class AppWalletUserRedis {

    private StringRedisTemplate stringRedisTemplate;


    private AppWalletUserRedis() {
        stringRedisTemplate = BeanUtil.getBean(StringRedisTemplate.class);
    }

    private enum Singleton {
        INSTANCE;
        private AppWalletUserRedis instance;

        // JVM会保证此方法绝对只调用一次
        Singleton() {
            instance = new AppWalletUserRedis();
        }
    }


    String cacheKey = RedisKeyConstant.LETOKNE_ADDRESS_USER;


    public static AppWalletUserRedis me() {
        return AppWalletUserRedis.Singleton.INSTANCE.instance;
    }


    public void put(String key, String value) {
        if (value != null) {
            stringRedisTemplate.opsForHash().put(cacheKey, key, value);
        }
    }


    public Object getValue(String key) {
        return stringRedisTemplate.opsForHash().get(cacheKey, key);
    }
}
